package com.wty.basic.reflect;

import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Author wangtengyu
 * @Create 2018-08-09-10:30
 */
public class MethodDemo {


    @Test
    public void test1() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
        Class clazz=Class.forName("com.wty.basic.reflect.Student");
        Student student= (Student) clazz.getConstructor().newInstance();
       // Method method[]=clazz.getMethods();
//        Method method[]=clazz.getDeclaredMethods();
//        for(Method m:method){
//            System.out.println(m);
//        }
        Method method=clazz.getDeclaredMethod("show4",int.class);
        method.setAccessible(true);
        System.out.println(method.invoke(student,5));
    }
}
